package com.quasar.hpatient.view.adapter;

import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.medicalmodel.AssayLinData;
import com.quasar.hpatient.utils.LogAndToastUtil;
import com.quasar.hpatient.utils.OutliersValues;
import com.quasar.hpatient.utils.Spanny;
import com.vise.log.ViseLog;

/**
 * author : 许建宏
 * Date: 2018/2/11 0011
 * View:
 */

public class AssayLinAdapter extends BaseQuickAdapter<AssayLinData, BaseViewHolder> {

    public AssayLinAdapter() {
        super(R.layout.assaylin_medicine);
    }

    @Override
    protected void convert(BaseViewHolder helper, AssayLinData item) {

        helper.setText(R.id.tv_time,item.getCreatTime().substring(5, 10));
        TextView textView=helper.getView(R.id.tv_val);

        if (OutliersValues.editTextNum(item.getItemValue())) {

            int tc = OutliersValues.TestingTextColor(
                    item.getItemValue(),
                    item.getStandardValue(),
                    item.getStandardValue(),0);
            textCore(tc, textView);

            Spanny spanny = new Spanny();
            if(tc==OutliersValues.UPNORMALVALUE){
                spanny.append(item.getItemValue(), new ForegroundColorSpan(color(R.color.values_err)));
                spanny.append("↑", new ForegroundColorSpan(color(R.color.values_err)));
            }else if(tc==OutliersValues.LOWNORMALVALUE){
                spanny.append(item.getItemValue(), new ForegroundColorSpan(color(R.color.values_di)));
                spanny.append("↓", new ForegroundColorSpan(color(R.color.values_di)));
            }else{
                spanny.append(item.getItemValue(), new ForegroundColorSpan(color(R.color.btcolor)));
            }
            textView.setText(spanny);
        }
    }


    private void textCore(int textColor, TextView tv) {

        ViseLog.d("检测到的异常值为"+textColor);
        switch (textColor) {
            //正常值
            case OutliersValues.NORMALVALUE:
                tv.setTextColor(color(R.color.btcolor));
                break;

            //大于最大值
            case OutliersValues.UPNORMALVALUE:
                tv.setTextColor(color(R.color.values_err));
                break;

            //小于最小值
            case OutliersValues.LOWNORMALVALUE:
                tv.setTextColor(color(R.color.values_di));
                break;


            case OutliersValues.DANGERLVALUE:
                tv.setTextColor(color(R.color.values_err));
                break;

            case OutliersValues.BOUNDARYVALUE:
                ViseLog.d("BOUNDARYVALUE" + OutliersValues.BOUNDARYVALUE);
                // msg.setError("请核对数据");
                break;

        }
    }

    private int color(int value) {
        return mContext.getResources().getColor(value);
    }
}
